<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>canvas</title>
    <style>
      #canvas {
        display: block;
        margin: 0 auto;
        border: 1px solid #eee;
      }
    </style>
  </head>
  <body>
    <canvas id="canvas" width="400" height="300"></canvas>
    <script>
      /** @type {HTMLCanvasElement} */
      let canvas = document.querySelector("#canvas");
      let ctx = canvas.getContext("2d");
      let pointX = ctx.canvas.width / 2;
      let pointY = ctx.canvas.height / 2;

      // 数量
      let num = 10;
      // 每个得角度
      let angle = (2 * Math.PI) / num;

      for (let i = 0; i < num; i++) {
        //   开始角度
        let startAngle = i * angle;
        // 结束角度
        let endAngle = (i + 1) * angle;
        ctx.beginPath();
        ctx.moveTo(pointX, pointY);
        ctx.arc(pointX, pointY, 100, startAngle, endAngle, false);
        ctx.lineTo(pointX, pointY);
        ctx.fillStyle = randomRgb();
        ctx.fill();
        ctx.stroke();
      }
      // 随机颜色
      function randomRgb() {
        let r = Math.floor(Math.random() * 256);
        let g = Math.floor(Math.random() * 256);
        let b = Math.floor(Math.random() * 256);
        return `rgb(${r},${g},${b})`;
      }
    </script>
  </body>
</html>
